﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using NUnit.Framework;
using Spring.Context;
using Spring.Context.Support;
using AdminCondominio.Negocio;
using AdminCondominio.Dominio;

namespace AdminCondominio.Pruebas
{

    [TestFixture]
    public class TestResidenteService
    {

       private IApplicationContext Spring;

       ResidenteService residenteService;
        [TestFixtureSetUp]
        public void InicializaPruebas() {

            Spring = new XmlApplicationContext(   
                "assembly://AdminCondominio/AdminCondominio/capaNegocio.xml",
                "assembly://AdminCondominio/AdminCondominio/capaPersistencia.xml"
              );

          residenteService = (ResidenteService)Spring.GetObject("residenteService");
          Assert.NotNull(residenteService);
        }

        [Test]
        public void TestCrearResidente() 
        {
         
           Residente residente = null;
           Assert.DoesNotThrow(delegate
            {
             //   residente = residenteService.CrearResidente("12345", "Alex Javier", new DateTime(2001, 12, 05), "alext@gmail.com", "12345");
            });
            Assert.NotNull(residente);
            Assert.Greater(residente.CoResidente,0);
        }
        [Test]
        public void TestIntentarCrearResidenteConDocumentoOCorreoRepetido()
        {
     
        
            Assert.Catch<Exception>(delegate
            {
                 //residenteService.CrearResidente("12345", "Luis", new DateTime(2001, 12, 05), "Luis@gmail.com", "12345");
            });
            Assert.Catch<Exception>(delegate
            {
                //residenteService.CrearResidente("123456", "Luis", new DateTime(2001, 12, 05), "alext@gmail.com", "12345");
            });
           
        }
        [Test]
        public void TestModificaResidente() 
        {
            
            Residente residenteAModificar = residenteService.ObtenerResidente("12345");
            Assert.NotNull(residenteAModificar);
            Assert.DoesNotThrow(delegate {
             //   residenteService.ModificarResidente("12345", "Alex Tomaylla", new DateTime(2001, 12, 05), "alext@gmail.com", "12345");
            });

        }
        [Test]
        public void TestListarResidente() 
        {
          
            String noresidente = null;
            ICollection<Residente> residente = null;
            Assert.DoesNotThrow(delegate
            {
                residente = residenteService.ListarResidentes(noresidente);
            });
            Assert.NotNull(residente);
        
        }

    }
}